import axios from 'axios';
import qs from 'qs';

const service = axios.create({
  baseURL: 'https://webcu.com.cn/voice/api/', // url = base url + request url
  timeout: 5000, // request timeout
});

service.interceptors.request.use(
  config => {
    config.data = qs.stringify(config.data);
    return config;
  },
  error => {
    console.log(error); // for debug
    return Promise.reject(error);
  },
);

service.interceptors.response.use(
  response => {
    const res = response.data;
    return res;
  },

  error => {
    console.log('err' + error);
    return Promise.reject(error);
  },
);

export default service;
